package com.example.day12.homework;

import java.util.Scanner;

public class TwoScannerCount {

    private int count=0;
    int a= (int) (Math.random()*10);
    int b= (int) (Math.random()*10);


    public synchronized void  printcount(){
        if(count!=0){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
        System.out.println("题目如下；"+a+"+"+b);
        count=1;
        notify();
    }

    public  synchronized  void  scannerCount(){
        if(count!=1){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("请输入结果：");
        Scanner scanner=new Scanner(System.in);
        int num=scanner.nextInt();
        System.out.println("你输入的结果是："+num);
        if (num==a+b){
            System.out.println("回答正确！！！");
        }else {
            System.out.println("回答错误！！！");
        }
        count=0;
        notify();
    }

}
class  TestResut{
    public static void main(String[] args) {
        TwoScannerCount two=new TwoScannerCount();
        new Thread(()-> two.printcount()).start();
        new Thread(()->two.scannerCount()).start();
    }
}
